import 'package:flutter/material.dart';

import 'package:get/get.dart';
import 'package:getx_learn/app/common/widgets/app_bar.dart';
import 'package:getx_learn/app/modules/navigation_demo/modules/navigation2/controllers/navigation2_controller.dart';

class Navigation2View extends GetView<Navigation2Controller> {
  const Navigation2View({Key? key}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    // 获取参数
    Map details = Get.arguments ?? {};
    // 获取参数
    Map? parameters = Get.parameters;

    return Scaffold(
      appBar: getAppBar(
        context: context,
        title: "Navigation2View",
      ),
      body: Center(
          child: ListView(
        children: [
          Text("(Get.arguments)传值 id = " + details["id"].toString()),
          Divider(),
          Text("(Get.parameters)传值 id = " + parameters["id"].toString()),
          Divider(),
          ListTile(
            title: Text("导航-返回"),
            subtitle: Text('Get.back()'),
            onTap: () => Get.back(),
          ),
          Divider(),
          _buildBackListTileRow(details,"Get.arguments"),
          Divider(),
          _buildBackListTileRow(parameters,"Get.parameters"),
        ],
      )),
    );
  }

  // https://dart.dev/tools/diagnostic-messages#unnecessary_non_null_assertion
  _buildBackListTileRow(Map? val,String type) {
    return val == null || val["id"] == null
        ? Container()
        : ListTile(
            title: Text("(${type})传值 id = " + val["id"].toString()),
            subtitle: Text('Get.back(result: {"success": true}'),
            onTap: () => Get.back(result: {"success": true}),
          );
  }
}
